package ATM.frame;

import ATM.service.UserService;
import ATM.service.impl.UserServiceImpl;
import ATM.util.DBUtil;
import ATM.pojo.UserDO;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class DepositPanel extends JPanel implements ActionListener {
    private JButton jButton1;
    private JButton jButton2;
    private JButton jButton3;

    private JLabel jLabel1;
    private JLabel jLabel2;

    private JTextField jTextField1;
    private JTextField jTextField2;

    private Icon buttonIcon1 = util.Util.getIcon("/images/buttonSure.jpg");
    private Icon buttonIcon2 = util.Util.getIcon("/images/buttonClear.jpg");
    private Icon buttonIcon3 = util.Util.getIcon("/images/buttonOff.jpg");

    private ATMmain atMmain;

    private UserService userService = new UserServiceImpl();

    public DepositPanel(ATMmain atMmain) {
        this.atMmain = atMmain;
        this.setLayout(null);

        this.setOpaque(false);

        jLabel1 = new JLabel("请输入存款金额");
        jLabel1.setBounds(300, 280, 250, 50);
        jLabel1.setForeground(Color.blue);
        jLabel1.setFont(new Font("宋体", Font.BOLD, 20));
        this.add(jLabel1);
        jTextField1 = new JTextField("");
        jTextField1.setBounds(500, 285, 200, 30);
        this.add(jTextField1);

        jLabel2 = new JLabel("请再次输入，确认金额");
        jLabel2.setBounds(250, 385, 300, 50);
        jLabel2.setForeground(Color.blue);
        jLabel2.setFont(new Font("宋体", Font.BOLD, 20));
        this.add(jLabel2);
        jTextField2 = new JTextField("");
        jTextField2.setBounds(500, 390, 200, 30);
        this.add(jTextField2);

        jButton1 = new JButton(buttonIcon1);
        jButton1.setBounds(210, 450, 140, 50);
        this.add(jButton1);
        jButton1.addActionListener(this);

        jButton2 = new JButton(buttonIcon2);
        jButton2.setBounds(450, 450, 140, 50);
        this.add(jButton2);
        jButton2.addActionListener(this);

        jButton3 = new JButton(buttonIcon3);
        jButton3.setBounds(690, 450, 140, 50);
        this.add(jButton3);
        jButton3.addActionListener(this);
    }

    public JLabel getjLabel1() {
        return jLabel1;
    }

    public void setjLabel1(JLabel jLabel1) {
        this.jLabel1 = jLabel1;
    }

    //存钱的函数
    /*public void deposit(double money){
        int a =Integer.parseInt(getDepositPanel().getjLabel1().getText());
    }*/

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == jButton1) {
            int money = Integer.parseInt(jTextField1.getText());
            userService.saveMoney(atMmain.getLoginUser().getId(),money);
            JOptionPane.showMessageDialog(atMmain, "存款成功，存入金额" + money);
            atMmain.switchPanel("menuPanel");
        } else if (e.getSource() == jButton2) {
            jTextField1.setText("");
            jTextField2.setText("");
            atMmain.switchPanel("depositPanel");
        } else if (e.getSource() == jButton3) {
            atMmain.switchPanel("loginPanel");
        }
    }
}
